#include <string.h>
#include <stdio.h>
#include "aes.h"
#include "../base64/base64.h"

extern "C"
{
	#include "ofo_net_aes.h"
	#include "dump.h"
}

void aes_encrypt(unsigned char *state,
                 unsigned char *key);
static void dumpCharArray(char *arrayName,char *array,int size)
{
	int i = 0;
	printf("%s: ",arrayName);
	while(i < size)
	{
		printf("0x%02X,",(unsigned char)array[i]);
		i++;
	}
	printf("\r\n");
}

#if 0
void aes_test()
{
	char data[16] ;
	unsigned char key[] ={0xA0,0xFD,0xCF,0xAF,0x39,0x45,0xB3,0x60,0xC8,0x4A,0x5A,0xAA,0x6F,0x6C,0x78,0x2E};
	char base64_out[64];
	int len = 0;

	strcpy((char *)data,"123453");
	aes_encrypt((unsigned char *)data,(unsigned char *)key);
	dumpCharArray("aes encrypt",data,16);
	base64_encode(data,16,base64_out,&len);
	printf("Base64 out[%d]= %s\n",len,base64_out);
	dumpCharArray("Base64 out",base64_out,len);
}
#endif

#if 1
void aes_test()
{
	char data[16] ;
	//a0 fd cf af 39 45 b3 60 c8 4a 5a aa 6f 6c 78 2e
	unsigned char key[] ={0xA0,0xFD,0xCF,0xAF,0x39,0x45,0xB3,0x60,0xC8,0x4A,0x5A,0xAA,0x6F,0x6C,0x78,0x2E};
	char base64_out[64];
	char aes_out[64];
	int aes_len = 0;
	int len = 0;

	char *base64_in = "ZvmXgsdt9Z/UuFvULURLTg==";

	strcpy((char *)data,"123453");
	aes_len = 64;
	AES128_EncryptECB(MODE_PKCS7_PADDING,(uint8_t *)data,16 ,(uint8_t *)aes_out,(uint32_t *)&aes_len,(uint8_t *)key);//MODE_PKCS7_PADDING  //MODE_NOPADDING
	dumpCharArray("aes encrypt out",aes_out,aes_len);
	base64_encode(aes_out,aes_len,base64_out,&len);
	printf("Base64 out[%d]= %s\n",len,base64_out);
	dumpCharArray("Base64 out",base64_out,len);



	base64_decode(aes_out,aes_len,base64_out,&len);
}
#endif